# 封装面包屑组件
from apps.goods.models import GoodsCategory


def get_breadcrumb(category_id):
    #1.获取三级分类的对象
    cat3 = GoodsCategory.objects.get(id=category_id)
    #2.三级---二级
    cat2 = cat3.parent
    #3.二级---一级
    cat1 = cat2.parent
    breadcrumb = {
        "cat1":{
            "id":cat1.id,
            "name":cat1.name,
            "url":cat1.goodschannel_set.all()[0].url
        },
        "cat2":cat2,
        "cat3":cat3,
    }
    return breadcrumb